package self.zhangkang.chart

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import self.zhangkang.chart.databinding.ActivityMainBinding

class StockDetailsActivity : AppCompatActivity() {

    private lateinit var mainBinding: ActivityMainBinding

    private val mStockDetailsViewModel: StockDetailsViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mainBinding = ActivityMainBinding.inflate(layoutInflater)
        title = "浦发银行"
        setContentView(mainBinding.root)
        initView()
    }

    override fun onResume() {
        super.onResume()
        mStockDetailsViewModel.setShareStock(Stock("600000", "SH"))
    }

    private fun initView() {
        mainBinding.viewPager2.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int {
                return 3
            }

            override fun createFragment(position: Int): Fragment {
                return when (position) {
                    0 -> AvgFragment()
                    1 -> FiveAvgFragment()
                    else -> KLineFragment()
                }
            }
        }
        TabLayoutMediator(mainBinding.tabLayout, mainBinding.viewPager2) { tab, position ->
            tab.text = when (position) {
                0 -> "分时"
                1 -> "五日"
                else -> "日K"
            }
        }.attach()
    }

}